package logic

import (
	"context"
	"store/model/mysql"
	"store/model/redis"
	"store/storerpc/internal/svc"
	"store/storerpc/storerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectLogic {
	return &CollectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectLogic) Collect(in *storerpc.CollectRequest) (*storerpc.CollectResponse, error) {
	// todo: add your logic here and delete this line

	var product mysql.Product
	mysql.DB.Debug().Model(&product).Where("id = ?", in.Userid).Find(&product)

	redis.Client.ZIncrBy("collectlist", 1, product.Product)

	return &storerpc.CollectResponse{Id: int64(product.ID)}, nil
}
